package com.itheima.utils;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;

import java.util.Map;

public class TokenMaker {
    private static final String signKey="itheima";
    private static final long expireTime=1000*60*60*24L;
    //生成token
    public static String makeToken(Map<String,Object>  map){
        String jwt= Jwts.builder()
                .signWith(io.jsonwebtoken.SignatureAlgorithm.HS256,signKey)//签名算法
                .addClaims(map)//添加自定义信息
                .setExpiration(new java.util.Date(System.currentTimeMillis()+expireTime))//设置过期时间
                .compact();
        return jwt;
    }
    //解析token
    public static Claims parseToken(String token){
        Claims claims=Jwts.parser()
                .setSigningKey(signKey)
                .parseClaimsJws(token)
                .getBody();
        return claims;
    }
}
